select
  accsub.accountSubjectId,
  accsub.subjectType,
  accsub.fullName,
  accsub.direction,
  subbal.registerTime,
  subbal.balanceMoney       
 from
  AccountSubjectBoImpl accsub      
 left join
  accsub.subjectBalanceList subbal         
 where
  accsub.accountSubjectId=subbal.accountSubject             
  and subbal.subjectBalanceId     =(
   select
    max(subbal2.subjectBalanceId)                    
   from
    SubjectBalanceBoImpl subbal2                    
   where
    subbal2.accountSubject=accsub.accountSubjectId                          
    and subbal2.boaType=0                          
    and subbal2.registerTime>=?
         and subbal2.registerTime<=?
     )
and (accsub.subjectType=3 
  or accsub.subjectType=4)
  and accsub.childrenSize <= 0   
order by
 accsub.subjectCode